# Server

## Description

Application that provides some balance operations.

## Getting Started

### Installing dependencies

To launch the application, it is enough to install Docker and Docker Compose.

| Dependence     | How to install                                                                |
|----------------|-------------------------------------------------------------------------------|
| Docker         | [Docker installation guide](https://docs.docker.com/engine/install/)          |
| Docker Compose | [Docker compose installation guide](https://docs.docker.com/compose/install/) |

The following dependencies will need to be installed for development.

| Development dependence                      | How to install                                                                                   |
|---------------------------------------------|--------------------------------------------------------------------------------------------------|
| Java 17+                                    | [Java installation example guide](https://techviewleo.com/install-java-openjdk-on-ubuntu-linux/) |
| Maven                                       | [Maven project](https://maven.apache.org/index.html)                                             |
| PostreSQL (Can be replaced by DB container) | [PostreSQL](https://www.postgresql.org/)                                                         |

### Running application

Since the server uses a database to store balances, the application is wrapped in docker compose.  
To run application execute:

```shell
docker compose up
```

To run application with rebuilt images execute:

```shell
docker compose up --build
```

Spring boot server will start on the 8080 port. DB will be available on the 5432 port.

To stop application execute:

```shell
docker compose down
```

### Api

| Method | Request                | Description                                     | Request body                            | Response body                                              |
|--------|------------------------|-------------------------------------------------|-----------------------------------------|------------------------------------------------------------|
| GET    | `/balance/<balanceId>` | Get balance amount by provided balance ID       |                                         | `200`: JSON `{"amount": number}`, `404`: balance not found |
| PUT    | `/balance/`            | Create balance with provided ID and start value | JSON `{"id": number, "amount": number}` | `200`: success, `400`: balance already exists              |
| POST   | `/balance/<balanceId>` | Update balance amount by provided balance ID    | JSON `{"id": number, "amount": number}` | `200`: JSON `{"amount": number}`, `404`: balance not found |
| DELETE | `/balance/`            | Purge all balances                              |                                         | `200`: success                                             |

## Developers

Michael Linker - *Entire work* - [Website](https://michaellinker.it)

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
